// 导入模块
const dbApi = require('../models/db')

// 文章图片、封面上传
exports.uploadArticleImage = async (req, res, next) => {
  try {
    // 处理请求
    res.status(201).json({
      image: {
        type: 1,
        img: `http://localhost:3000/public/article/image/${req.file.filename}`
      }
    })
  } catch (error) {
    next(error)
  }
}

// 素材图片上传
exports.uploadMatterImage = async (req, res, next) => {
  try {
    sql = `INSERT INTO images (url,collected) VALUES 
    ('http://localhost:3000/public/matter/image/${req.file.filename}',0)`
    // 处理请求
    await dbApi.query(sql)
    res.status(201).json({
      message: 'Successed'
    })
  } catch (error) {
    next(error)
  }
}
